using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    public class DBAControl
    {
        #region Local Variable
        private DBADataAccess _DBADAO;
        #endregion Local Variable

        #region Method
        public DBAControl()
        {
            _DBADAO = new DBADataAccess();
        }

        public DBAInfo Get(
            String DB
        , ref string sErr)
        {
            return _DBADAO.Get(
            DB
            , ref sErr);
        }

        public DataTable GetAll(
        ref string sErr)
        {
            return _DBADAO.GetAll(
            ref sErr);
        }

        public Int32 Add(DBAInfo obj, ref string sErr)
        {
            //BUS.OBJ_APPDETControl ctr = new OBJ_APPDETControl();
            //ctr.GenTable(obj.DB);
            //BUS.OBJ_APPHDRControl ctr1 = new OBJ_APPHDRControl();
            //ctr1.GenTable(obj.DB);
            //BUS.OBJ_LOGControl ctr2 = new OBJ_LOGControl();
            //ctr2.GenTable(obj.DB);

            return _DBADAO.Add(obj, ref sErr);
        }

        public string Update(DBAInfo obj)
        {
            return _DBADAO.Update(obj);
        }

        public string Delete(
            String DB
        )
        {
            //OBJ_ARLDGControl tmpARLDG = new OBJ_ARLDGControl();
            //tmpARLDG.DropTable(DB);
            return _DBADAO.Delete(
            DB
            );
        }
        public Boolean IsExist(
            String DB
        )
        {
            return _DBADAO.IsExist(
            DB
            );
        }

        /*  public string Delete(String arrID)
          {
              string kq = "";
              string[] arrStrID = arrID.Split(',');
              foreach (string strID in arrStrID)
              {
                  if (strID != "")
                  {
                      int ID = Convert.ToInt32(strID);
                      kq += _DBADAO.Delete(ID);
                  }
              }
              return kq;
          } 
		
          public DataTableCollection Get_Page(DBAInfo obj, string orderBy, int pageIndex, int pageSize,ref String sErr)
          {
              return _DBADAO.Get_Page(obj, orderBy, pageIndex, pageSize, ref sErr);
          }*/

        public DataTable Search(String columnName, String columnValue, String condition, String tableName, ref String sErr)
        {
            return _DBADAO.Search(columnName, columnValue, condition, tableName, ref  sErr);
        }

        #endregion Method


        internal DataTable GetTransferOut(ref string sErr)
        {
            throw new NotImplementedException();
        }

        internal DataTable ToTransferInStruct()
        {
            DataTable dt = new DataTable("DBA");
            dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn("DB", typeof(String)),
				new DataColumn("DB1", typeof(String)),
				new DataColumn("DB2", typeof(String)),
				new DataColumn("DESCRIPTION", typeof(String)),
				new DataColumn("DATE_FORMAT", typeof(String)),
				new DataColumn("DECIMAL_PLACES_SUNACCOUNT", typeof(String)),
				new DataColumn("DECIMAL_SEPERATOR", typeof(String)),
				new DataColumn("THOUSAND_SEPERATOR", typeof(String)),
				new DataColumn("PRIMARY_BUDGET", typeof(String)),
				new DataColumn("DATA_ACCESS_GROUP", typeof(String)),
				new DataColumn("DECIMAL_PLACES_SUNBUSINESS", typeof(String)),
				new DataColumn("REPORT_TEMPLATE_DRIVER", typeof(String))
				});
            return dt;
        }

        internal string InsertUpdate(DBAInfo dBAInfo)
        {
            string sErr = "";
            if (IsExist(dBAInfo.DB))
                sErr = Update(dBAInfo);
            else Add(dBAInfo, ref sErr);

            return sErr;

        }

       
        public string TransferIn(DataRow row)
        {
            return InsertUpdate(new DBAInfo(row));
        }
    }
}
